<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/iconfont.css"/>
		<style>		
			body{background: #fff;}	 		
			
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a id="btnClose" class="mui-action-hide mui-icon iconfont icon-close mui-pull-left"></a>
			<button type="button" id="btnRegister" class="mui-btn-link mui-pull-right">注册</button>
			<h1 class="mui-title"></h1>
		</header>
		<div class="mui-content mui-content-form">
			<h3 class="mui-text-center" style="padding: 30px 0;">短信验证登录</h3>
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row authCode">
					<input id='MobileNo' type="tel" oninput="if(value.length>13)value=value.slice(0,13)" onkeyup="formatMobile(this)" class="mui-input-clear mui-input" maxlength="13" placeholder="请输入手机号">
					<button type="button" id="btnSendAuthCode" class="mui-btn-mini" data-type="登录" data-check="0">发送验证码</button>
				</div>
				<div class="mui-input-row">
					<input id='authcode' type="password" class="mui-input-clear mui-input" maxlength="4" placeholder="请输入短信验证码">
				</div>
			</form>
			<div class="mui-content-padded pt-10">
				<button id='login' type="button" class="mui-btn mui-btn-block mui-btn-danger">登录</button>
			</div>
			<div class="mui-content-padded oauth-area">

			</div>
			<div class="mui-content-padded">
				<div class="mui-grid-view mui-row">
					<div class="mui-col-xs-6"><a href="javascript:;" class="open-window" data-url="login.html">密码登录</a></div>
					<div class="mui-col-xs-6 mui-text-right"><a href="javascript:;" id="btnForget">忘记密码</a></div>
				</div>
			</div>
		</div>
		<script src="js/mui.js"></script>
		<script src="js/mui.enterfocus.js"></script>
		<script src="js/app.js"></script>
		<script>
			var $btnClose = document.getElementById("btnClose");
			var showType = 0;
						
			setShowType = function(type) {
				showType = type;
				
                if(type == 1){
                	$btnClose.style.display = "none";
                	
                	mui.oldBack = mui.back;
					var backButtonPress = 0;
					mui.back = function(event) {
						backButtonPress++;
						if(backButtonPress > 1) {
							plus.runtime.quit();
						} else {
							plus.nativeUI.toast('再按一次退出应用');
						}
						setTimeout(function() {
							backButtonPress = 0;
						}, 1000);
						return false;
					};
                }
                else{
                	mui.back = mui.oldBack;
                }
	        };
	           
	        document.getElementById("btnForget").addEventListener('tap', function () {
	        	mui.openWindow("forget-password.html", "forget-password");
	        });
	        
	        document.getElementById("btnRegister").addEventListener('tap', function () {
	        	mui.openWindow("register.html", "register");
	        });
	           
			(function($, doc) {
				$.init();
								
				$.plusReady(function() {
					var settings = app.getSettings();
					var state = app.getState();
					
					var loginButton = doc.getElementById('login');
					var accountBox = doc.getElementById('MobileNo');
					var $authcode = doc.getElementById('authcode');
					var regButton = doc.getElementById('reg');
					var forgetButton = doc.getElementById('forgetPassword');
					
					accountBox.value = state.account || "";
					
					loginButton.addEventListener('tap', function(event) {						
						var loginInfo = {
							account: accountBox.value.replace(/\s/g,""),
							authcode: $authcode.value
						};
						if(loginInfo.account=="" || loginInfo.authcode==""){
							mui.toast("请输入");
							return false;
						}
						app.login(loginInfo, function(error) {
							mui.hideLoading();
							if (error) {
								mui.toast(error);
								return;
							}
							else{
								var launch = plus.webview.getLaunchWebview();
								launch.evalJS("refresh(true)");
								launch.show();	
							}
						});
					});
					
					$.enterfocus('#login-form input', function() {
						$.trigger(loginButton, 'tap');
					});
				});
			}(mui, document));
		</script>
	</body>

</html>